﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Somnus.Core.SceneManager;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using FarseerPhysics.Collision;
using Somnus.Utils;
using Somnus.Objects;
using Somnus.Core;
using Somnus.Objects.GameObjects.Characters;
using Somnus.Objects.GameObjects.LevelObjects;

namespace Somnus.Scenes
{

    class Level1 : SceneBase
    {

        public DreamWorld world;
        public PhysicsObject personagem;
        public DebugView debugView;
        public Texture2D texture;

        public override void start()
        {
            world = new DreamWorld(new Vector2(0, 20), 100f);
            personagem = new Indio(world, "personagem", Game1.getInstance().Content.Load<Texture2D>("DreamKids"), new Rectangle(0, 0, 291, 152), 0.5f, false, 0, 0, 291 * 0.6f, 120 * 0.6f, 0);
            Voador inimigo = new Voador(world, "inimigo", Game1.getInstance().Content.Load<Texture2D>("voador"), null, 0.5f, false, 0,0, 100, 50, 0);
            Platform chao = new Platform(world, "platform01", Game1.getInstance().Content.Load<Texture2D>("bringel"), null, 0.5f, true, 0, 200, 1600, 30, 0);
            Sensor sensor = new Sensor(world, "sensor", 0.5f, true, 0, 400, 4000, 30, 0);
            world.addBG(1, "Layer1");
            world.addBG(4, "Layer2");
            chao.Rotation = 00;
            //personagem.body.IgnoreCollisionWith(chao.body);
            personagem.art.Animation = "Correndo";
            personagem.art.ScaleX = personagem.art.ScaleY = 0.6f;
            personagem.scaleArt = false;
            chao.body.Awake = false;
            world.camera.offsetY = Game1.getInstance().graphics.PreferredBackBufferHeight / 4;
            Console.WriteLine(world.getObjectsByType(typeof(PhysicsObject)).Count);
            
        }
        
        public override void update(GameTime gameTime)
        {
            world.Step((float)(gameTime.ElapsedGameTime.TotalMilliseconds * 0.001));
            world.update(gameTime);
            //world.camera.Pos = Vector2.Lerp(world.camera.Pos, new Vector2(personagem.x, personagem.y), 0.1f);
            world.camera.Pos = new Vector2(personagem.x, personagem.y);
            world.ClearForces();
            
        }

        public override void draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            world.draw(gameTime, spriteBatch);
        }

        public override void terminate()
        {

        }


       
    }
}
